package cn.ichiva.dl.tushare.analy;

import cn.ichiva.dl.tushare.common.AgentConfig;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.inputs.InputType;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.LSTM;
import org.deeplearning4j.nn.conf.layers.RnnOutputLayer;
import org.deeplearning4j.nn.weights.WeightInit;
import org.nd4j.linalg.activations.Activation;

/**
 * 第二阶段人工智能配置
 */
public class AgentConfig2442 implements AgentConfig {

    private static final AgentConfig2442 instance = new AgentConfig2442();

    @Override
    public int getInput() {
        return 17;
    }

    @Override
    public int getOutput() {
        return 3;
    }

    @Override
    public MultiLayerConfiguration getMultiLayerConfiguration() {
        int nIn = getInput();
        int nOut = getOutput();

        return new NeuralNetConfiguration.Builder()
                .seed((long) (Math.random() * Long.MAX_VALUE))
                .weightInit(WeightInit.XAVIER)
                .list()
                .layer(0, new LSTM.Builder().nIn(nIn).nOut(nIn * 2).activation(Activation.SOFTSIGN).build())
                .layer(1, new DenseLayer.Builder().nIn(nIn * 2).nOut(nIn * 4).activation(Activation.IDENTITY).build())
                .layer(2, new LSTM.Builder().nIn(nIn * 4).nOut(nIn * 8).activation(Activation.SOFTSIGN).build())
                .layer(3, new DenseLayer.Builder().nIn(nIn * 8).nOut(nIn * 4).activation(Activation.IDENTITY).build())
                .layer(4, new DenseLayer.Builder().nIn(nIn * 4).nOut(nIn * 2).activation(Activation.IDENTITY).build())
                .layer(5, new RnnOutputLayer.Builder().activation(Activation.SOFTMAX).nIn(nIn * 2).nOut(nOut).build())
                .pretrain(false).backprop(true)
                .setInputType(InputType.recurrent(nIn))
                .build();
    }

    public static AgentConfig2442 getInstance(){
        return instance;
    }
}
